import datetime

from django.db import models

# Create your models here.

class User(models.Model):
    nickname = models.CharField(max_length=32,unique=True)
    phone = models.CharField(max_length=32)
    email = models.CharField(max_length=32)
    password = models.CharField(max_length=255)

class Article(models.Model):
    category = models.CharField(max_length=100,verbose_name="分类",null=False)
    title = models.CharField(max_length=100,verbose_name="标题")
    author = models.CharField(max_length=50,verbose_name="作者")
    abstract = models.CharField(max_length=500,verbose_name="文章摘要",null=False)
    content = models.TextField(verbose_name="文章内容")
    c_time = models.DateTimeField(auto_now_add=True,verbose_name="创建日期")
    like_num=models.IntegerField(verbose_name="点赞数",default=0)
    reply_num = models.IntegerField(verbose_name="回复数", default=0)
    read_num = models.IntegerField(verbose_name="阅读数", default=0)
    # against_num = models.IntegerField(verbose_name="反对数", null=True)
    class Meta:
        verbose_name_plural="文章发布"
        verbose_name="文章发布"

class LogInfo(models.Model):
    type_dict_choice=[(0,"阅读"),(1,"点赞"),(2,"拍砖")]
    types=models.IntegerField(verbose_name="分类",choices=type_dict_choice)
    user=models.ForeignKey(User,on_delete=models.CASCADE)
    c_time=models.DateTimeField(auto_now_add=True,verbose_name="创建日期")
    class Meta:
        verbose_name_plural="点评信息"
        verbose_name="点评信息"

class ContentInfo(models.Model):
    user=models.ForeignKey(User,on_delete=models.CASCADE)
    article=models.ForeignKey(Article,on_delete=models.CASCADE)
    c_time=models.DateTimeField(auto_now_add=True,verbose_name="创建日期")
    content=models.TextField(verbose_name="文章内容")
    class Meta:
        verbose_name_plural="文章评论"
        verbose_name="文章评论"


class CommentInfo(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    article=models.ForeignKey(Article,on_delete=models.CASCADE)
    c_time=models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
    content=models.TextField(verbose_name="文章内容")
    class Meta:
        ordering=("-c_time",)
        verbose_name_plural="文章评论"
        verbose_name="文章评论"